package com.googlecode.garbagecan.jmsstudy.activemq.topic;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class TopicSubscriberSync {
	public static void main(String[] args) throws JMSException {
		ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
		Connection connection = factory.createConnection();
		connection.start();
		
		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		Topic topic = session.createTopic("myTopic.messages");

		MessageConsumer consumer = session.createConsumer(topic);
		while (true) {
			Message message = consumer.receive(1000);
			if (message != null) {
				TextMessage tm = (TextMessage) message;
				System.out.println("Received message: " + tm.getText());
			}
		}
//		session.close();
//		connection.stop();
//		connection.close();
	}
}
